import { createSlice } from '@reduxjs/toolkit'
const routeSlice = createSlice({
    name: 'routeMenus',
    initialState: {
        routes: sessionStorage.getItem('menuList')?JSON.parse(sessionStorage.getItem('menuList')):[],
    },
    reducers: {
        // 不需要返回值，因为这里的所有代码要被整合成一个reducer，统一返回state
        filterRouter(state, action) {
            state.routes = action.payload
        },
    }
})

// 手动导出action方法，返回值为{type:**, {payload:[传的值]}}
export const { filterRouter, completeById, deleteById } = routeSlice.actions
// 异步action方法：使用redux-toolkit内置的redux-thunk中间件
export const filterRouterAsync = (value) => {
    return async dispatch => {
        dispatch(filterRouter(value))
    }
}
// 默认导出reducer
export default routeSlice.reducer

